//
//  BaseViewController.m
//  BGM
//
//  Created by liuqin on 2018/11/25.
//  Copyright © 2018年 com.alirtc.demo. All rights reserved.
//

#import "BaseViewController.h"
#import "Common.h"
#import "BGMUser.h"
#import <NIMSDK/NIMSDK.h>
#import "MessageListViewController.h"
#import "MessageAcceptViewController.h"
#import "PushMessageViewController.h"
#import "BaseTabBarViewController.h"


#import "CommonViewController.h"
#import "BGMHTTP.h"
#import "BGMPushView.h"


@interface BaseViewController ()<UIGestureRecognizerDelegate,BGMPushViewDelegate>

@property (nonatomic,strong)BGMPushView *pushView;

@end

@implementation BaseViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tabBarController.tabBar.hidden = YES;
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(pushDic:) name:@"APP_PUSHMESSAGE" object:nil];
    
    
    self.navigationController.navigationBarHidden = YES;
    self.view.backgroundColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:1];
 
    
    self.navview  = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, kNavBarHeight+kStatusBarHeight)];

    [self.navview setImage:[UIImage imageNamed:@"navImage"]];
    [self.view addSubview:self.navview];
    self.navview.hidden = YES;
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.navview.frame.size.height-50, SCREENW, 50)];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.textColor = bgmmainColor;
    self.titleLabel.font = [UIFont systemFontOfSize:22];
    [self.navview addSubview:self.titleLabel];
    self.titleLabel.hidden = YES;
    
    
    self.topBackView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREENW+60, SCREENH/3+50)];
    [self.topBackView setImage:[UIImage imageNamed:@"group_7"]];
    [self.view addSubview:self.topBackView];
    self.topBackView.hidden = YES;
    
    
    
    
    self.mormalLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.navview.frame.size.height, SCREENW, SCREENH-self.navview.frame.size.height)];
    self.mormalLabel.text = @"暂无内容";
    self.mormalLabel.textColor = bgmsmallColor;
    self.mormalLabel.font = [UIFont systemFontOfSize:25];
    self.mormalLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.mormalLabel];
    self.mormalLabel.hidden = YES;
    
    
    //读取沙盒数据
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    NSDictionary *userDic = [ud objectForKey:usermessage];
    BGMUser *user = [BGMUser shareInstance];
    user.userId = [NSString stringWithFormat:@"%@",[userDic objectForKey:@"usersId"]];
    user.userToken = [NSString stringWithFormat:@"%@",[userDic objectForKey:@"token"]];
    user.imToken = [NSString stringWithFormat:@"%@",[userDic objectForKey:@"imToken"]];
    user.headImage =  [NSString stringWithFormat:@"%@",[userDic objectForKey:@"headImage"]];
 
    user.isOpenContactStore =  [NSString stringWithFormat:@"%@",[ud objectForKey:@"isOpenContactStore"]];
    self.backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, self.navview.frame.size.height-kNavBarHeight,kNavBarHeight , kNavBarHeight)];
    [self.backBtn setImage:[UIImage imageNamed:@"backImage"] forState:UIControlStateNormal];
    [self.view addSubview:self.backBtn];
    [self.backBtn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
    self.backBtn.hidden = YES;
    
    //添加按扭
    [self setBtn];
 }
- (void)setBtn{
    //返回按扭
    if (self.navigationController.viewControllers.count > 1) {
        self.backBtn.hidden = NO;
    }
    //title
    self.titleBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.backBtn.frame.size.width, self.backBtn.frame.origin.y, 50, self.backBtn.frame.size.height)];
    [self.titleBtn setTitleColor:bgmmainColor forState:UIControlStateNormal];
    self.titleBtn.titleLabel.font = [UIFont boldSystemFontOfSize:22];
    self.titleBtn.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.titleBtn];
    self.titleBtn.hidden = YES;
    
    
    self.navRightBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW-kNavBarHeight-20, self.navview.frame.size.height-kNavBarHeight,kNavBarHeight , kNavBarHeight)];
    [self.navRightBtn setTitle:@"完成" forState:UIControlStateNormal];
    [self.view addSubview:self.navRightBtn];
    [self.navRightBtn addTarget:self action:@selector(clickRight) forControlEvents:UIControlEventTouchUpInside];
    self.navRightBtn.hidden = YES;

}

- (void)clickRight{
}
- (void)clickBack{
    [self.navigationController popViewControllerAnimated:YES];
}


 

#pragma mark 发布
-(void)pushDic:(NSNotification *)noti{
    
    NSDictionary *notifiy =  noti.object;
    NSDictionary *pushDic = [notifiy objectForKey:@"dic"];
    NSArray *array = [notifiy objectForKey:@"array"];
    PushMessageViewController *vc = [[PushMessageViewController alloc]init];
    vc.typeArray = array;
    vc.titleStr = [NSString stringWithFormat:@"%@",[pushDic objectForKey:@"name"]];
    vc.typeId = [NSString stringWithFormat:@"%@",[pushDic objectForKey:@"id"]];
    UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:vc];

    [self.navigationController presentViewController:nc animated:YES completion:nil];
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"HidenPushView" object:nil];
    
    
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceivePress:(UIPress *)press{
    return YES;
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
@end
